<template>
  <div class="page_root" :key="queryUpdateFlag" data-page-name="工单配置" data-page-identification="e_pqrozsghx5">
    <a-spin :spinning="pageLoading.loading" :tip="pageLoading.tip">
      <!-- begin vid_tlrkjj4v2f 自定义模板_qwqbncei0u -->
      <div class="gd-setting">
        <div class="setting-title">消息推送频率</div>
        <a-form :model="settingState.msgForm" ref="settingRef">
          <div class="msg-form">
            <a-row :gutter="12">
              <a-col>
                <span class="msg-title"> 工单超时每日提醒： </span>
              </a-col>
              <a-col>
                <a-form-item>
                  <a-checkbox v-model:checked="settingState.msgForm.check" />
                </a-form-item>
              </a-col>
              <a-col>
                <a-form-item
                  label="上午"
                  :rules="[
                                        {
                                            required: settingState.msgForm.check ? true : false,
                                            message: '请选择触发时间',
                                            trigger: 'blur'
                                        }
                                    ]"
                  name="amTime"
                >
                  <a-time-picker v-model:value="settingState.msgForm.amTime" value-format="HH:mm:ss"
                /></a-form-item>
              </a-col>
              <a-col>
                <a-form-item
                  label="下午"
                  :rules="[
                                        {
                                            required: settingState.msgForm.check ? true : false,
                                            message: '请选择触发时间',
                                            trigger: 'blur'
                                        }
                                    ]"
                  name="pmTime"
                >
                  <a-time-picker v-model:value="settingState.msgForm.pmTime" value-format="HH:mm:ss" />
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter="12">
              <a-col>
                <span class="msg-title"> 子工单超时每日提醒： </span>
              </a-col>
              <a-col>
                <a-form-item>
                  <a-checkbox v-model:checked="settingState.msgForm.subCheck" />
                </a-form-item>
              </a-col>
              <a-col>
                <a-form-item
                  label="上午"
                  :rules="[
                                        {
                                            required: settingState.msgForm.subCheck ? true : false,
                                            message: '请选择触发时间',
                                            trigger: 'blur'
                                        }
                                    ]"
                  name="subAmTime"
                >
                  <a-time-picker v-model:value="settingState.msgForm.subAmTime" value-format="HH:mm:ss"
                /></a-form-item>
              </a-col>
              <a-col>
                <a-form-item
                  label="下午"
                  :rules="[
                                        {
                                            required: settingState.msgForm.subCheck ? true : false,
                                            message: '请选择触发时间',
                                            trigger: 'blur'
                                        }
                                    ]"
                  name="subPmTime"
                >
                  <a-time-picker v-model:value="settingState.msgForm.subPmTime" value-format="HH:mm:ss" />
                </a-form-item>
              </a-col>
            </a-row>
          </div>
        </a-form>
        <a-col>
          <a-button type="primary" @click="handleSubmitSetting" :loading="settingState.msgBtnLoading">保存</a-button>
        </a-col>
      </div>
      <!-- end vid_tlrkjj4v2f 自定义模板_qwqbncei0u -->
    </a-spin>
  </div>
</template>
<script setup lang="tsx">
  import {
      h, ref, reactive, toRaw, markRaw, watch, computed,
      onBeforeMount, onMounted, onBeforeUnmount, onUnmounted, onActivated, onDeactivated
    } from "vue";
    import { useRoute, useRouter } from 'vue-router';
    const router = useRouter();
    const route = useRoute();
    import { get, post, put, del, request, requestWithHeaders } from '@/utils/http/Axios';
    import { cloneDeep, localGet, merge, getDifferenceArray, traversalTreeStructure, checkCaseCondition, renderStringInTemplate, handleBreadcrumbJump, throttle, permission, getComponentParamsValue } from '@/utils/index';
    import { isNullOrEmpty, isEmptyArr, isNullOrUnDef, isContained, isArray, isEmpty, isObject } from '@/utils/is';
    import dayjs from 'dayjs';
    import { getPagePcChartsDataSourceConvert } from '@/utils/chart';
    import { message, notification, Modal } from 'ant-design-vue'
    import { propertyFormatByNumber, propertyFormatByPercentage, propertyFormatByDate, parseSubFromDataList } from '@/utils/format';
    import colorTheme from '@/design/custom-theme.json';
    
    import UserTableRecords from '@/model/UserTableRecords';
    import { getAppBaseUrl } from '@/utils/index';
    import { sendToken } from "@/hooks/useIframeToken";
    import { useSystemStore } from "@/store/modules/system";
    const systemStore = useSystemStore();
    



      // 获取传入的流程ID和组件参数
      const props = defineProps({
            'processInstanceId': {
            type: [String,Number,Boolean],
            default: undefined,
        },
      })
      const immediateWatch = (source, callback) => {
        watch(source, callback, {deep: true,immediate: true })
      }



  /* -------------------------- 属性定义 -------------------------- */

      const setTimeOutList = [];
      const pageLoading = reactive({
        loading: false,
        tip: undefined
      });
      const authInfo = localGet('app-user-store');




      // 处理校验
      const setSubFormName =(parentInfo, name)=>{
        return [parentInfo.parents, parentInfo.cycleIndex, name];
      }


  /* ========================== 属性定义 ========================== */


  /* -------------------------- 元素数据引用 -------------------------- */


  /* ========================== 元素数据引用 ========================== */


  /* -------------------------- 页面数据 -------------------------- */


  /* ========================== 页面数据 ========================== */



  /* -------------------------- 响应 -------------------------- */

  /* ========================== 响应 ========================== */


  /* -------------------------- 函数 -------------------------- */

  /* ========================== 函数 ========================== */


  /* -------------------------- 页面参数 -------------------------- */

    const pageParameter_state = reactive({
        'processInstanceId': props.processInstanceId ?? route.query.processInstanceId,
    })

  /* ========================== 页面参数 ========================== */


  /* -------------------------- 组件事件处理方法 -------------------------- */

    // ---------------------------- 组件数据同步 ----------------------------

    // ============================ 组件数据同步 ============================


  /* ========================== 组件事件处理方法 ========================== */


  /* -------------------------- 生命周期 -------------------------- */
  // 用于参数变更后重新执行自定义指令
      const queryUpdateFlag = ref(0);
      onMounted(() => { ;

    });

    onUnmounted(() => {
      // 销毁定时器
      setTimeOutList.forEach(({ repeat, timer }) => {
        repeat ?  clearInterval(timer): clearTimeout(timer);
      });
    });

  /* ========================== 生命周期 ========================== */


  /* -------------------------- 数据关联处理 -------------------------- */





  /* -------------------------- 表单数据同步 -------------------------- */
  /* ========================== 表单数据同步 ========================== */

  /* ========================== 数据关联处理 ========================== */


  /* -------------------------- 不同组件自定义的处理逻辑 -------------------------- */

  /* ========================== 不同组件自定义的处理逻辑 ========================== */


  // ================================定制化逻辑========================================
  onMounted(() => {
          getSetting()
      })
      const settingState = reactive({
          msgForm: {
              check: false,
              subCheck: false,
              amTime: undefined,
              pmTime: undefined,
              subAmTime: undefined,
              subPmTime: undefined
          },
          msgBtnLoading: false
      })
      const settingRef = ref(null)
      function handleSubmitSetting() {
          settingRef.value
              .validate()
              .then(() => {
                  settingState.msgBtnLoading = true
                  put(
                      '/solution-ppm/api/v2/built-in-system-ppm/work_order_template/setting_timeout_frequency',
                      settingState.msgForm
                  ).then(data => {
                      if (data.code !== 200) {
                          message.error(data.message)
                          return
                      }
                      message.success(data.message)
                      getSetting()
                  })
              })
              .finally(() => {
                  settingState.msgBtnLoading = false
              })
      }
      // 限制上午时间：只能选择 00:00 - 12:00
      const disabledAmTime = () => {
          return {
              disabledHours: () => [...Array(24).keys()].slice(13, 24) // 禁用 13 - 23 点
          }
      }

      // 限制下午时间：只能选择 13:00 - 23:59
      const disabledPmTime = () => {
          return {
              disabledHours: () => [...Array(24).keys()].slice(0, 13) // 禁用 0 - 12 点
          }
      }
      function getSetting() {
          get('/solution-ppm/api/v2/built-in-system-ppm/work_order_template/get_timeout_frequency').then(data => {
              if (data.code !== 200) {
                  message.error(data.message)
                  return
              }
              Object.assign(settingState.msgForm, data.data)
          })
      }
</script>
<style lang="less" scoped>
  .page_root {
  width: 100%;
  height: 100%;
  overflow: auto;
  }
  .page_root :deep(.@{ant-prefix}-spin-nested-loading),
  .page_root :deep(.@{ant-prefix}-spin-container)
   {
      height: 100%;
  }
  .page_root :deep(.@{ant-prefix}-spin-container .@{ant-prefix}-table-wrapper)
   {
      display: flex;
      flex-flow: column nowrap;
      justify-content: flex-start;
  }
  .page_root :deep(.@{ant-prefix}-table)
   {
    flex: auto;
    overflow: auto;
  }
  .table-moreBtn_down {
    overflow: hidden; white-space: nowrap; text-overflow: ellipsis; width: 100px;
  }

  .table-moreBtn_menu :deep(.table-moreBtn_menu-item):hover {
    background: #ebf1ff;
  }

  /*  表格树结构样式处理，展开按钮层级增加*/
  :deep(.@{ant-prefix}-table-row-expand-icon) {
    z-index: 1;
  }
  /*  表格树结构 由于每个表格项采用自定义组件，使用绝对定位布局，开启树结构导致显示异常，暂时使用层级定位位置 */
  :deep(.@{ant-prefix}-table-row-level-1 .@{ant-prefix}-table-cell-with-append .cell-wrapper-left) {
    left: 15px !important;
    width: calc(100% - 15px);
  }
  :deep(.@{ant-prefix}-table-row-level-2 .@{ant-prefix}-table-cell-with-append .cell-wrapper-left) {
    left: 30px !important;
    width: calc(100% - 30px);
  }
  :deep(.@{ant-prefix}-table-row-level-3 .@{ant-prefix}-table-cell-with-append .cell-wrapper-left) {
    left: 45px !important;
    width: calc(100% - 45px);
  }
  :deep(.@{ant-prefix}-table-row-level-4 .@{ant-prefix}-table-cell-with-append .cell-wrapper-left) {
    left: 60px !important;
    width: calc(100% - 60px);
  }

  /* 穿梭框改变默认样式，为根据组件样式控制左右栏宽度。 */
  :deep(.@{ant-prefix}-transfer-list)
   {
      height: 100%;
      width: 50%;
  }


  /*工单配置*/
      .gd-setting {
          height: 100%;
          background-color: #fff;
          padding: 24px;
      }
      .setting-title {
          height: 16px;
          font-size: 16px;
          line-height: 16px;
          padding-left: 8px;
          border-left: 4px solid #3875ff;
          font-size: 16px;
          color: #262626;
          letter-spacing: 0;
          font-weight: 600;
          margin-bottom: 16px;
      }
      .msg-title {
          font-size: 14px;
          color: #595959;
          font-weight: 400;
          height: 32px;
          line-height: 32px;
          display: inline-block;
          width: 150px;
      }
      .msg-form :deep(.ant3-form-item-label) {
          width: 55px;
      }
      /*工单配置*/
</style>